package com.ruoyi.forApp.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.shiro.service.LoginService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.system.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

//安卓端登陆认证(无验证码)
@Controller
public class LoginControllerForApp extends BaseController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/loginForApp")
    @ResponseBody
    public Map<String,Object> ajaxLogin(String username, String password)
    {
        Map<String,Object> map=new HashMap<>();
        try
        {
            User user=loginService.login(username,password);
            map.put("success",true);
            map.put("userId",user.getUserId());
        }
        catch (Exception e)
        {
            String msg = "用户或密码错误";
            if (StringUtils.isNotEmpty(e.getMessage()))
            {
                msg = e.getMessage();
            }
            map.put("success",false);
            map.put("msg",msg);

        }
        return map;
    }
}
